﻿using AutoMapper;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using SassModule.Contracts;
using SassModule.Entity;
using SassModule.ViewModel;
using System;

namespace SassModule.Controllers
{
    /// <summary>
    /// 菜单
    /// </summary>
    [ApiController]
    [Route("Sass/[controller]")]
    public class MenuController : ControllerBase
    {
        private readonly ILogger _logger;
        private readonly IWebHostEnvironment _env;
        private readonly IMenuService _service;
        private readonly IMapper _mapper;
        /// <summary>
        /// ctor
        /// </summary>
        /// <param name="mapper"></param>
        /// <param name="logger"></param>
        /// <param name="env"></param>
        /// <param name="service"></param>
        public MenuController(IMapper mapper,ILogger<MenuController> logger, IWebHostEnvironment env, IMenuService service)
        {
            _logger = logger;
            _env = env;
            _service = service;
            _mapper = mapper;
        }
        /// <summary>
        /// 登录之后根据用户Id获取菜单列表
        /// </summary>
        /// <returns></returns>
        [HttpGet("{id}")]
        public IActionResult Index([FromRoute]Guid id)
        {
            string db = Common.GetHeader4DB(this.Request);
            return Ok(new ResponseData(null,_service.Index(id, db)));
        }

        /// <summary>
        /// 获取账套下的菜单列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Index()
        {
            string db = Common.GetHeader4DB(this.Request);
            return Ok(new ResponseData(null, _service.Index(db)));
        }
    }
}
